package com.example.minefieldkeepercloud.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.bean.BrandlAndModelBean;
import com.king.base.adapter.ViewHolderAdapter;
import com.king.base.adapter.holder.ViewHolder;

import java.util.ArrayList;
import java.util.List;

public class GridModeAdapter extends ViewHolderAdapter<BrandlAndModelBean.DataBean.BasemodelBean> {
    private Context context;
    private int selectedPos=-1;//选中的id 没有为-1
    private List<BrandlAndModelBean.DataBean.BasemodelBean> listData_new=new ArrayList<>();
    private List<String> list=new ArrayList<>();
    public GridModeAdapter(Context context, List<BrandlAndModelBean.DataBean.BasemodelBean> listData) {
        super(context, listData);
        this.context = context;

    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, BrandlAndModelBean.DataBean.BasemodelBean string, int position) {
        return inflate(R.layout.adapter_brand);
    }

    @Override
    public void bindViewDatas(ViewHolder holder, BrandlAndModelBean.DataBean.BasemodelBean bean, final int position) {
        holder.setText(R.id.tv_content,bean.getModel());
        if (list.contains(position+""))
        {
            //选中的项
            ((TextView)holder.getView(R.id.tv_content)).setTextColor(context.getResources().getColor(R.color.white));
            ((TextView)holder.getView(R.id.tv_content)).setBackgroundResource(R.drawable.menu_select_bg);
        }else
        {
            ((TextView)holder.getView(R.id.tv_content)).setTextColor(context.getResources().getColor(R.color.black));
            ((TextView)holder.getView(R.id.tv_content)).setBackgroundResource(R.drawable.menu_noselect_bg);
        }

    }

    /**
     * 设置选中
     * @param i
     */
    public void setSelected(String str)
    {
        //selectedPos=i;
        if(list.contains(str))
            list.remove(str);
        else
            list.add(str);

        notifyDataSetChanged();
    }

    /**
     * 展开
     * @param bln_show
     */
    public void isShow(boolean bln_show,List<BrandlAndModelBean.DataBean.BasemodelBean> listData)
    {
       if(bln_show)
       {
           listData_new.clear();
           if(listData.size()>3)
           {
               for (int i=0;i<3;i++)
               {
                   listData_new.add(listData.get(i));
               }
               setListData(listData_new);
               notifyDataSetChanged();
           }
           else
           {
               listData_new.addAll(listData);
               setListData(listData_new);
               notifyDataSetChanged();
           }
       }
       else
       {
           setListData(listData);
           notifyDataSetChanged();
       }
    }

    /**
     * 设置选中id
     */
    public int getSelectedPos() {
        return selectedPos;
    }
}
